<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xalan="http://xml.apache.org/xalan"
	xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="xalan">

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

<xsl:attribute-set name="title"> 
     <xsl:attribute name="font-weight">bold</xsl:attribute> 
     <xsl:attribute name="color">#0000A0</xsl:attribute> 
     <xsl:attribute name="font-family">Times</xsl:attribute> 
</xsl:attribute-set>

<xsl:attribute-set name="link"> 
     <xsl:attribute name="color">#0033cc</xsl:attribute> 
</xsl:attribute-set>

<xsl:attribute-set name="row">
</xsl:attribute-set> 

<xsl:attribute-set name="cell"> 
     <xsl:attribute name="padding-top">3px</xsl:attribute>
     <xsl:attribute name="border-style">solid</xsl:attribute>
     <xsl:attribute name="border-color">#FFFFFF</xsl:attribute>
     <xsl:attribute name="border-width">1px</xsl:attribute>
</xsl:attribute-set>

<xsl:template name="DrawPage">
	<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
	  <fo:layout-master-set>
	    <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="1.5cm" margin-bottom="1.5cm" margin-left="2cm" margin-right="1.5cm">
	      <fo:region-body region-name="page-body"/>
	      <fo:region-after region-name="page-footer"/>
	    </fo:simple-page-master>
	  </fo:layout-master-set>
	  <fo:page-sequence initial-page-number="1" master-reference="simpleA4">
	  	<fo:title>CV: <xsl:value-of select="name"/> (<xsl:value-of select="email"/>)</fo:title>
	  	<!-- 
  		<fo:static-content flow-name="page-footer">
	  		<fo:block text-align="right" border-bottom-style="solid" border-bottom-color="#CCCCCC" border-bottom-width="1px" color="#CCCCCC">Page <fo:page-number id="page"/> of <fo:page-number-citation ref-id="end"/></fo:block>
  		</fo:static-content>
  		 -->
	    <fo:flow flow-name="page-body">
	      <fo:block font-family="Arial" font-size="12px">
				<fo:table table-layout="fixed" width="100%">
				
				<fo:table-column column-width="35mm"/>
				<fo:table-column column-width="140mm"/>
				
				<fo:table-body>
			      	<xsl:apply-templates/>
				</fo:table-body>
				
				</fo:table>
				
	      </fo:block>
	      <fo:block id="end"></fo:block>
	    </fo:flow>
	  </fo:page-sequence>
	</fo:root>
</xsl:template>

<xsl:template name="DrawRow">
  	<xsl:param name="labelKey"/>
  	<xsl:param name="label">
		<xsl:call-template name="i18n"><xsl:with-param name="key" select="$labelKey"/></xsl:call-template>
  	</xsl:param>
  	<xsl:param name="value"/>
  	<xsl:param name="body"/>
	<fo:table-row>
        <fo:table-cell xsl:use-attribute-sets="title cell">
        	<fo:block><xsl:value-of select="$label"/>:</fo:block>
        </fo:table-cell>
        <fo:table-cell xsl:use-attribute-sets="cell">
        	<xsl:if test="$value">
		        <fo:block>
	        	<xsl:if test="$labelKey = 'name'">
		        	<xsl:attribute name="font-weight">bold</xsl:attribute>
		        	<xsl:attribute name="font-size">14px</xsl:attribute>
		        </xsl:if>
		        <xsl:choose>
		        	<xsl:when test="$labelKey = 'email'">
						<fo:basic-link xsl:use-attribute-sets="link">
							<xsl:attribute name="external-destination">mailto:<xsl:value-of select="$value"/></xsl:attribute>
			  				<xsl:value-of select="$value"/>
						</fo:basic-link>
		  			</xsl:when>
		        	<xsl:when test="$labelKey = 'web-site'">
						<fo:basic-link xsl:use-attribute-sets="link">
							<xsl:attribute name="external-destination"><xsl:value-of select="$value"/></xsl:attribute>
			  				<xsl:value-of select="$value"/>
						</fo:basic-link>
		  			</xsl:when>
		  			<xsl:otherwise>
			        	<xsl:value-of select="$value"/>
		  			</xsl:otherwise>
	  			</xsl:choose>
	  			</fo:block>
  			</xsl:if>
        	<xsl:if test="$body">
	 			<xsl:copy-of select="$body"/>
	 		</xsl:if>
        </fo:table-cell>
	</fo:table-row>
</xsl:template>

<xsl:template name="DrawRightColumn">
	<xsl:param name="body"/>
	<fo:table-row xsl:use-attribute-sets="row">
		<fo:table-cell xsl:use-attribute-sets="cell"><fo:block> </fo:block></fo:table-cell>
		<fo:table-cell xsl:use-attribute-sets="cell">
			<fo:block text-align="justify"><xsl:copy-of select="$body"/></fo:block>
		</fo:table-cell>
	</fo:table-row>
</xsl:template>

<xsl:template name="DrawGroup">
  	<xsl:param name="labelKey"/>
	<fo:table-row xsl:use-attribute-sets="row">
	     <fo:table-cell xsl:use-attribute-sets="cell" number-columns-spanned="2"
	     	border-bottom-style="solid" border-bottom-color="#CCCCCC" border-bottom-width="1px">
			<fo:block xsl:use-attribute-sets="title">
				<xsl:call-template name="i18n"><xsl:with-param name="key" select="$labelKey"/></xsl:call-template>
			</fo:block>
		 </fo:table-cell>
	</fo:table-row>
	<xsl:apply-templates/>
</xsl:template>

 <xsl:template name="insertBlocksByBreaks">
   <xsl:param name="pText"/>

   <xsl:choose>
     <xsl:when test="not(contains($pText, '&#xA;'))">
       <fo:block><xsl:value-of select="$pText"/></fo:block>
     </xsl:when>
     <xsl:otherwise>
       <fo:block><xsl:value-of select="substring-before($pText, '&#xA;')"/></fo:block>
       <xsl:call-template name="insertBlocksByBreaks">
         <xsl:with-param name="pText" select="substring-after($pText, '&#xA;')"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>

</xsl:stylesheet>